package com.wskeee.ec.managers
{
	import flash.display.Stage;
	import flash.events.Event;
	
	import com.wskeee.ec.interfaces.IEComponent;
	
	public class RenderManager implements IRenderManager
	{
		/**
		 * 保存需要更新的组件引用
		 */
		private var invalidates:Vector.<IEComponent> = new Vector.<IEComponent>(); 
		
		public function RenderManager(stage:Stage)
		{
			stage.addEventListener(Event.ENTER_FRAME,onRenderEnterFrame);
		}
		
		protected function onRenderEnterFrame(event:Event):void
		{
			validate();
		}
		
		/**
		 * 更新所有标记更新的组件 
		 * 
		 */
		private function validate():void
		{
			while(properties.length>0)
				properties.shift().validateProperties();
			while(sizes.length>0)
				sizes.shift().validateSize();
			while(displayLists.length>0)
				displayLists.shift().validateDisplayList();
		}
		
		/**
		 * 添加组件标记 
		 * @param obj
		 * 
		 */
		public function invalidate(obj:IEComponent):void
		{
			invalidates.push(obj);
		}
		
		//---------------------
		//invalidateProperties
		//---------------------
		private var properties:Vector.<IEComponent> = new Vector.<IEComponent>();
		public function invalidateProperties(obj:IEComponent):void
		{
			properties.push(obj);
		}
		
		//---------------------
		//invalidateSize
		//---------------------
		private var sizes:Vector.<IEComponent> = new Vector.<IEComponent>();
		public function invalidateSize(obj:IEComponent):void
		{
			sizes.push(obj);
		}
		
		//---------------------
		//invalidateDisplayList
		//---------------------
		private var displayLists:Vector.<IEComponent> = new Vector.<IEComponent>();
		public function invalidateDisplayList(obj:IEComponent):void
		{
			displayLists.push(obj);
		}
		
		public function validateNow():void
		{
			validate();
		}
	}
}